package com.qf.controller;

import com.qf.pojo.DtsAdmin;
import com.qf.pojo.DtsBrand;
import com.qf.pojo.DtsComment;
import com.qf.service.DtsBrandService;
import com.qf.service.DtsCommentService;
import com.qf.util.ResponseUtil;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/comment")
public class AdminCommentController {

    @Autowired
    DtsCommentService commentService;

    @Autowired
    DtsBrandService brandService;

    @PostMapping("/delete")
    public Object delete(@RequestBody DtsComment comment){
        commentService.deleteById(comment.getId());

        return ResponseUtil.ok();
    }

    @GetMapping("/list")
    public Object list(@RequestParam(value = "page",required = false,defaultValue = "1")Integer page,
                       @RequestParam(value = "limit",required = false,defaultValue = "10")Integer limit,
                       @RequestParam(value = "sort",required = false,defaultValue = "add_time")String sort,
                       @RequestParam(value = "order",required = false,defaultValue = "desc")String order,
                       String userId,String valueId){
//        //判断是否为品牌制造商
//        Subject subject = SecurityUtils.getSubject();
//        DtsAdmin admin = (DtsAdmin) subject.getPrincipal();
//        List<Integer> brandsId = null;
//        if (subject.hasRole("品牌制造商")){
//            //查询品牌id
//            brandsId = brandService.findBrandIdsByAdminId(admin.getId());
//        }

        Map<String,Object> data = commentService.findByPage(page,limit,sort,order,userId,valueId);

        return ResponseUtil.ok(data);

    }
}
